package com.demo.bean9001.controller.news;

import com.demo.bean9001.service.news.NewsService;
import com.demo.common.entity.News;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 新闻动态
 * 作者：张佑威
 * 补充：孙佳佳
 * 分配任务：张改
 * 插入数据：张佑威
 */
@RestController
public class NewsController {
    @Autowired
    private NewsService newsService;

    /**
     * 新闻分页展示
     * @param pagenum
     * @return
     */
    @GetMapping("/News")
    public List<News> selectAll(@RequestParam(value = "pagenum") Integer pagenum){
        List<News> search = newsService.search( (pagenum - 1) * 4);
        return search;
    }

    /**
     * 通过ID查看新闻动态详情
     * @param NewId
     * @return
     */
    @GetMapping("/News/{NewId}")
    public News selectById(@PathVariable("NewId") Integer NewId){
        return newsService.selectByNewsId(NewId);
    }

    //查询新闻子类及文章
    @GetMapping("/News/getnews")
    public List<News> newsManager(@RequestParam(value = "id",required = true) Integer id,
                                  @RequestParam(value = "pagenum",required = false,defaultValue = "1") Integer pagenum){
        System.out.println(newsService.newsproduct(id,(pagenum - 1) * 4));
        return newsService.newsproduct(id,(pagenum - 1) * 4);
    }
}
